﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Microsoft.BizTalk.TestTools.Mapper;
using Microsoft.BizTalk.TestTools.Schema;
using System.IO;
using System.Diagnostics;

namespace Acme.SalesOnline.Tests.Maps
{
    /// <summary>
    /// Tests for the map
    /// </summary>
    [TestClass]
    public class Claim_To_ClaimServiceRequestTests
    {
        /// <summary>
        /// Performs a basic standard test
        /// </summary>
        [TestMethod]
        public void StandardTest()
        {
            const string inputFileName = @"..\..\..\Acme.SalesOnline.Tests\Maps\Claim_To_ClaimServiceRequestTests_StandardTest_Input.xml";
            const string outputFileName = "Claim_To_ClaimServiceRequestTests_StandardTest_Output.xml";
            const string ExpectedFileName = @"..\..\..\Acme.SalesOnline.Tests\Maps\Claim_To_ClaimServiceRequestTests_StandardTest_Expected.txt";
            
            //Run the map and produce an output
            TestableMapBase map =  new Acme.SalesOnline.Maps.Claim_To_ClaimServiceRequest();
            map.TestMap(inputFileName, InputInstanceType.Xml, outputFileName, OutputInstanceType.XML);
            

            //Validate that the output is exactly as we expect
            byte[] expected = File.ReadAllBytes(ExpectedFileName);
            byte[] output = File.ReadAllBytes(outputFileName);            
            bool passed = false;
            if (expected.Length == output.Length)
            {
                for (int index = 0; index <= expected.Length - 1; index++)
                {
                    if (expected[index] != output[index])                    
                        break;                    
                }
                passed = true;
            }

            if (!passed)
            {
                Debug.WriteLine("Expected File: ");
                Debug.WriteLine(File.ReadAllText(ExpectedFileName));
                Debug.WriteLine("Output File: ");
                Debug.WriteLine(File.ReadAllText(outputFileName));
            }
            Assert.IsTrue(passed, "The map output was not as expected");
        }
    }
}
